package cn.ecnu.mapper;

import cn.ecnu.pojo.HelpRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HelpRecordMapper {

    /**
     * 根据督导ID获取求助记录
     *
     * @param supervisorId 督导ID
     * @return 求助记录列表
     */
    @Select("SELECT * FROM psychology.help_record WHERE to_id = #{id}")
    List<HelpRecord> getHelpRecordBySupervisorId(@Param("id") Integer supervisorId);

    @Select("SELECT * FROM psychology.help_record WHERE help_record_id = #{id}")
    HelpRecord getHelpRecordById(@Param("id") Integer recordId);

    // 某个督导今天完成的求助数
    @Select("select count(*) from psychology.help_record where date(datetime)=curdate() and to_id=#{uid}")
    int getCountToday(Integer uid);

    // 某个督导今天完成的求助时长
    @Select("select sum(psychology.help_record.duration) from psychology.help_record where date(datetime)=curdate() and to_id=#{uid}")
    int getTimeToday(Integer uid);


    int insertHelpRecord(HelpRecord helpRecord);

    int updateHelpRecordById(HelpRecord helpRecord);
}
